package com.wanmait.happyheating;
import com.wanmait.happyheating.interceptor.UserinfoInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class WebConfig implements WebMvcConfigurer
{
    @Resource
    private UserinfoInterceptor userinfoInterceptor;

    /**
     *配置全局跨域
     * @author yuQianTao
     * @since 2021-05-17
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("*")
                .allowedHeaders("*")
                .maxAge(3600);

    }
    /**
     *配置JWT拦截器
     * @author 郭振鹏
     * @since 2021 05 19
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(userinfoInterceptor)
                .addPathPatterns("**/userinfo/**");
//        System.out.println("index...................................");

    }
    /**
     *设置图片存放路径
     * @author yuQianTao
     * @since 2021-06-02
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/adminImages/**").addResourceLocations("classpath:/static/adminImages/");
        //registry.addResourceHandler("/adminImages/**").addResourceLocations("src/main/resources/static/adminImages/");
        //registry.addResourceHandler("/images/**").addResourceLocations("file:D:/uploadImages/");
    }
}
